package juc;

import lombok.SneakyThrows;

public class EndThread {

    private static class UseThread extends Thread{

        @SneakyThrows
        @Override
        public void run() {

            String threadName = Thread.currentThread().getName();
            while (Thread.interrupted()){
                System.out.println(threadName+"is running flag = "+isInterrupted());
            }
            System.out.println(threadName+"is running flag = "+isInterrupted());

        }
    }

    public static void main(String[] args) throws InterruptedException {

        UseThread useThread = new UseThread();
        useThread.start();
        Thread.sleep(2000);
        useThread.join();
        useThread.interrupt();
    }

}
